package com.atguigu.gmall.juc.CAS;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/1 13:36
 */
public class CASTest implements Runnable{
    private  volatile int value;

    public   int compareandSwarp(int oldevalue,int newvalue){
         if (value==oldevalue){
             value = newvalue;
         }
         return newvalue;
    }

    @Override
    public void run() {
        compareandSwarp(0,1);
    }

    public static void main(String[] args) throws InterruptedException {
        CASTest casTest = new CASTest();
        casTest.value = 0;
        Thread t1= new Thread(casTest);
        Thread t2= new Thread(casTest);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(casTest.value);
    }
}
